package achievement

import (
	"gddgame.cc/galaxy/common/dsl/game"
	"gddgame.cc/galaxy/utils"
)

//go:generate msgp

//msgp:tuple UserAchievement
type UserAchievement struct {
	Id     int         `json:"id" msg:"id"`
	Date   string      `json:"date" msg:"date"`
	Goal   int         `json:"goal" msg:"goal"`
	Extend interface{} `json:"extend" msg:"extend"`
}

//msgp:tuple Achievement
type Achievement struct {
	Id     int         `json:"id" msg:"id"`
	Key    string      `json:"key" msg:"key"`
	Type   int         `json:"type" msg:"type"`
	Name   string      `json:"name" msg:"name"`
	Desc   string      `json:"desc" msg:"desc"`
	Icon   string      `json:"icon" msg:"icon"`
	Goal   int         `json:"goal" msg:"goal"`
	Score  int         `json:"score" msg:"score"`
	Sort   int         `json:"sort" msg:"sort"`
	Extend interface{} `json:"extend" msg:"extend"`

	*game.DataExtend `json:"-" msg:"-"`
}

func NewAchievement(provider *game.DataProvider, achievement *SettingAchievement) *Achievement {
	extend := game.NewDataExtend(utils.ToString(achievement.Id), achievement.UpdateTime).Add("name", achievement.Name).Add("desc", achievement.Desc)
	ext := &Achievement{
		Id:         achievement.Id,
		Type:       achievement.Type,
		Name:       provider.LanguageKey(extend.Inline(), "name"),
		Desc:       provider.LanguageKey(extend.Inline(), "desc"),
		Icon:       achievement.Icon,
		Goal:       int(achievement.GetGoal()),
		Score:      achievement.Score,
		Sort:       achievement.Sort,
		Extend:     achievement.Extend,
		DataExtend: extend,
	}
	return ext
}
